﻿using System;
using System.Collections.Generic;
using System.Web;
using Siyarem.Database;
using System.Data;

namespace DAL
{
    public class DataDB : QueryDB
    {
        public DataDB() : base(Sabitler.ConstantProvider.APP_CONNSTR_KEY) { }

        public DataTable UrunListesiGetir(int categoryID, int typeID)
        {
            List<ParameterPair> parameters = new List<ParameterPair>();
            parameters.Add(new ParameterPair("@CATEGORY_ID", categoryID));
            parameters.Add(new ParameterPair("@TYPE_ID", typeID));

            return ExecuteForDataTable("URUN_LISTELE", CommandType.StoredProcedure, parameters);
        }

        public DataRow UrunGetir(int productID)
        {
            List<ParameterPair> parameters = new List<ParameterPair>();
            parameters.Add(new ParameterPair("@ID", productID));

            return ExecuteForDataRow("URUN_GETIR", CommandType.StoredProcedure, parameters);
        }

        public int UrunEkle(int typeID, int categoryID, string productName, string productOverView, string productDetail, decimal price, string logo)
        {
            List<ParameterPair> parameters = new List<ParameterPair>();
            parameters.Add(new ParameterPair("@TYPE_ID", typeID));
            parameters.Add(new ParameterPair("@CATEGORY_ID", categoryID));
            parameters.Add(new ParameterPair("@PRODUCT_NAME", productName));
            parameters.Add(new ParameterPair("@PRODUCT_OVERVIEW", productOverView));
            parameters.Add(new ParameterPair("@PRODUCT_DETAIL", productDetail));
            parameters.Add(new ParameterPair("@PRICE", price));
            //parameters.Add(new ParameterPair("@LOGO", logo));

            return Convert.ToInt32(ExecuteForScalar("URUN_EKLE", CommandType.StoredProcedure, parameters));
        }

        public int UrunGuncelle(int productID, int typeID, int categoryID, string productName, string productOverView, string productDetail, decimal price, string logo)
        {
            List<ParameterPair> parameters = new List<ParameterPair>();
            parameters.Add(new ParameterPair("@ID", productID));
            parameters.Add(new ParameterPair("@TYPE_ID", typeID));
            parameters.Add(new ParameterPair("@CATEGORY_ID", categoryID));
            parameters.Add(new ParameterPair("@PRODUCT_NAME", productName));
            parameters.Add(new ParameterPair("@PRODUCT_OVERVIEW", productOverView));
            parameters.Add(new ParameterPair("@PRODUCT_DETAIL", productDetail));
            parameters.Add(new ParameterPair("@PRICE", price));
            //parameters.Add(new ParameterPair("@LOGO", logo));

            return ExecuteForNonQuery("URUN_GUNCELLE", CommandType.StoredProcedure, parameters);
        }

        public DataTable KategoriListesiGetir(int typeID)
        {
            List<ParameterPair> parameters = new List<ParameterPair>();
            parameters.Add(new ParameterPair("@TYPE_ID", typeID));

            return ExecuteForDataTable("KATEGORI_LISTELE", CommandType.StoredProcedure, parameters);
        }

        public DataRow IcerikGetir(int contentID, string contentName)
        {
            List<ParameterPair> parameters = new List<ParameterPair>();
            parameters.Add(new ParameterPair("@ID", contentID));
            parameters.Add(new ParameterPair("@CONTENT_NAME", contentName));

            return ExecuteForDataRow("ICERIK_GETIR", CommandType.StoredProcedure, parameters);
        }

        public int IcerikEkle(string contentName, string header, string content)
        {
            List<ParameterPair> parameters = new List<ParameterPair>();
            parameters.Add(new ParameterPair("@CONTENT_NAME", contentName));
            parameters.Add(new ParameterPair("@HEADER", header));
            parameters.Add(new ParameterPair("@CONTENT", content));

            return Convert.ToInt32(ExecuteForScalar("ICERIK_EKLE", CommandType.StoredProcedure, parameters));
        }
    }
}
